<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
 <script type="text/javascript" src="<c:url value="/js/jquery.js"/>"></script>
    <script type="text/javascript">
	  
	  $(document).ready(function(){
	     
	     //alert($("select"));
	     //var s=document.getElementsByTagName("select");
	     //alert(s);
	     
	     //当前选中的下拉框
	     var currentSelect;
	     //当前父类别选项的值
         var currentValue="";
	  
        //住下拉框发生改变时，做出响应
         $("select").change(function(){
         
          currentSelect=$(this);
          currentValue=currentSelect.val();
          
          if(currentValue==0){
        	  alert("aaa");
        	//  document.all['oopp'].length=0;
        	  var d=document.getElementById("oopp");
              d.style.display='none';
              return "";
          }
          
          $.post("<c:url value="/category"/>",{"act":"getChildCategory","parentNo":currentValue,"seed":Math.random()},
            function(data){
              
                if(data.length!=0){
                    var ss=$("<div id='ddd'></div>");
                    var ch=$("<select id='oopp'></select>").appendTo(ss);
           //        var childSelect=$("<select id='oopp'></select>");
                    $("<option>=请选择=</option>").appendTo(ch);
                   
					
                 //   var str="<option id='oopp'>=请选择=</option>";
                  //  alert("");
                 //   $("<select></select>").html(str);
                     var obj=eval("("+data+")");
                    for(i=0;i<obj.employee.length;i++){
                      $("<option value='"+obj.employee[i].categoryNo+"'>"+obj.employee[i].categoryName+"</option>").appendTo(ch);
                    }
                 
                    ch.insertAfter(currentSelect);
                    
                }
                else{
                    alert("无下级层次");
                    var d=document.getElementById("oopp");
            	    d.style.display='none';
                } 
          
          });//end post()
          
        });//end change
        
        //表单提交的时候进行检测
        $("form").submit(function(){
            alert("dfd");
            //判断空
            if(isContainsNull()){
                return false;
            }
            
            //对类别名称进行检查
            var ctgName=$(":input[name=ctg_name]").val();
            
            //类别名称的长度限制
            if(ctgName.length<2||ctgName.length>15){
               alert("类别名称的长度为3-15,请检查!");
               return false;
            }
            //不能为纯数字
            if(!isNaN(ctgName)){
               alert("类别名称不能为纯数字,请检查!");
               return false;
            }
            
            //查看并设置父类别编号的值
          /*  if(currentValue==""){
               alert("父类别没有选择,请检查!");
               return false;
            }else{*/
         //      $(":input[name=ctg_p_no]").val(currentValue);
            
            
            //测试
       //     alert($(":input[name=ctg_p_no]").val());
       //    alert(currentValue);
            return true;
            
        });//end submit

	  });// end ready
	  
	  //查看是否有空项
	  function isContainsNull(){
	      
	      var containsNull=false;
	      //检测是否有没有填写的内容
          $(":input").each(function(){
              var currentInput=$(this);
              if(currentInput.val()==""){
              
                  var currentInputName=currentInput.attr("name");
                  if(currentInputName=="ctg_no"){
                      alert("类别编号没有填写,请检查!");
                  }
                  else if(currentInputName=="ctg_name"){
                      alert("类别名称没有填写,请检查!");
                  }
                  
                  containsNull=true;              
              }
          });//end each
          return containsNull;
 
	  }
	  
	</script>

  </head>
  
  <body>
      <div class="title">
          <h3>更新类别信息</h3>
          <hr/>
      </div>
     <div class="wrapper">
          <form class="content_form" action="<c:url value="/category"/>" method="post">
              <input type="hidden" name="act" value="update"/>
              <div class="wrapper_div">
                  <span>请选择父类别:</span>
                  <select class="main_select" name="ctg_p_no">
                     
                      <c:forEach items="${categoryList}" var="ctg">
                        <option value="${ctg.categoryNo}" <c:if test="${ctg.categoryNo==category.categoryParentNo}">selected="selected"</c:if> >${ctg.categoryName}</option>
                      </c:forEach>
                  </select>
              </div>
              <div class="wrapper_div">
                  <span>类别编号:</span>
                  <input name="ctg_no" readonly="readonly" value="${category.categoryNo}"/>
              </div>
              <div class="wrapper_div">
                  <span>类别名称:</span>
                  <input name="ctg_name" value="${category.categoryName }"/>
              </div>
              <div class="wrapper_div">
                  <input type="submit" value="提交"/> 
                  <input type="reset" value="重置"/>
              </div>
              
          </form>
      </div>
      <!-- 去参考java1204的后台登入 -->
      <c:if test="${not empty error}">
                 <script type="text/javascript">
                   alert("${error}");
                 </script>
      </c:if>
  </body>
</html>

          